Component({
  options: {},
  /**
   * 组件的属性列表
   */
  properties: {
    // 数据源
    itemObj: {
      type: Object,
    },
    // 序号
    index: {
      type: Number,
      value: null,
    },
    keyword: {
      type: String,
      value: "",
    },
    showPhone: {
      type: Boolean,
      value: true,
    },
    showDis: {
      type: Boolean,
      value: true,
    },
    nameType: {
      type: String,
      value: "1",
    },
    showGz: {
      type: Boolean,
      value: false,
    },
    showTab: {
      type: Boolean,
      value: true,
    },
    disabled: {
      type: Boolean,
      value: false,
    },
    ShowWithdraw: {
      type: Boolean,
      value: false,
    },
  },

  /**
   * 组件的初始数据
   */
  data: {},

  /**
   * 组件的方法列表
   */
  methods: {
    phone (event) {
      console.log(event.currentTarget.id);
      if (event.currentTarget.id) {
        wx.makePhoneCall({
          phoneNumber: event.currentTarget.id,
        });
      } else {
        wx.showToast({
          icon: "none",
          title: "暂无电话",
        });
      }
    },

    withdraw (event) {
      console.log(event.currentTarget.id);
      let opType = event.currentTarget.dataset.optype;
      let para={}
      if (opType == 'single') {
        let id = event.currentTarget.id;
        if (id) {
          wx.showModal({
            title: "提示",
            content: "撤回后原指定客户经理将无法看到该走访记录，是否撤回？",
            success: (res) => {
              if (res.confirm) {
                console.log("用户点击确定");
                para.optype='single'
                para.id=id
                this.triggerEvent("withdraw", para);
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
        } else {
          wx.showToast({
            icon: "none",
            title: "参数无效",
          });
        }
      }else if (opType == 'batch') {
        let batchId = event.currentTarget.id;
        if (batchId) {
          wx.showModal({
            title: "提示",
            content: "按批次撤回将撤回该批次下所有未走访记录，是否撤回？",
            success: (res) => {
              if (res.confirm) {
                console.log("用户点击确定");
                para.optype='batch'
                para.batchId=batchId
                this.triggerEvent("withdraw", batchId);
              } else if (res.cancel) {
                console.log("用户点击取消");
              }
            },
          });
        } else {
          wx.showToast({
            icon: "none",
            title: "参数无效",
          });
        }
      }
    },

    location (e) {
      if (!e.currentTarget.dataset.one.longitude) return;
      const longitude = this.transMarker1([
        e.currentTarget.dataset.one.longitude,
        e.currentTarget.dataset.one.latitude,
      ])[0];
      const latitude = this.transMarker1([
        e.currentTarget.dataset.one.longitude,
        e.currentTarget.dataset.one.latitude,
      ])[1];
      console.log(latitude,longitude,e.currentTarget.dataset.one.d2CorpName,e.currentTarget.dataset.one.d2Dom,'需要传的参数')
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        name: e.currentTarget.dataset.one.d2CorpName,
        address: e.currentTarget.dataset.one.d2Dom,
        scale: 18,
      });
    },
    // 跳转到详情页面
    toprodetail (e) {
      if (e.currentTarget.dataset.disabled) {
        // 根据企业状态点击操作
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '吊销')) {
          wx.showToast({
            title: `该企业已于${e.currentTarget.dataset.proitem.writeoffDate}吊销`,
            icon: 'none'
          })
          return
        }
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '注销')) {
          wx.showToast({
            title: `该企业已于${e.currentTarget.dataset.proitem.writeoffDate}注销`,
            icon: 'none'
          })
          return
        }
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '吊销后注销')) {
          wx.showToast({
            title: `该企业已于${e.currentTarget.dataset.proitem.writeoffDate}注销`,
            icon: 'none'
          })
          return
        }
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '迁出')) {
          wx.showToast({
            title: '该企业已迁出',
            icon: 'none'
          })
          return
        }
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '其他')) {
          return
        }
        if (e.currentTarget.dataset.proitem.labelList.some(pre => pre.name == '个体户撤销')) {
          return
        }
      }
      console.log(e.currentTarget.dataset.proitem)
      this.triggerEvent("toprodetail", e.currentTarget.dataset.proitem);
    },
    goGz (e) {
      this.triggerEvent("goGz", e.currentTarget.dataset.type);
    },
    // 中心点坐标转化
    transMarker1 (item) {
      const resae = gcoord.transform(
        [item[0], item[1]],
        gcoord.BD09, // 当前坐标系
        gcoord.GCJ02 // 目标坐标系
      );
      return resae;
    },
  },
});
